package com.eyeem.recyclerviewtools.sample;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.transition.Explode;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.eyeem.recyclerviewtools.sample.data.Data;
import com.eyeem.recyclerviewtools.util.Views;
import com.squareup.picasso.Picasso;

public class DetailActivity extends AppCompatActivity {
    ViewHolder views;
    int size;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        setContentView(R.layout.activity_detail);
        // 设置一个exit transition
        getWindow().setExitTransition(new Explode());//new Slide()  new Fade()
//        Window.setEnterTransition()：设置进入动画
//        Window.setExitTransition()：设置退出效果
//        Window.setSharedElementEnterTransition()：设置共享元素的进入动画
//        Window.setSharedElementExitTransition()：设置共享元素的退出动画


        views = new ViewHolder(this);
        //添加菜单和返回按钮
        setSupportActionBar(views.toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        views.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //
        Data data = (Data) getIntent().getSerializableExtra("ItemInfo");
        size = getResources().getDisplayMetrics().widthPixels;
        Picasso.with(this)
                .load(data.photoUrl.replace("/h/100", "/h/" + size))
                //.resize(data.size, data.size)
                .noFade()
                //.placeholder(placeholder(data.profileUrl))
                .into(views.image);
        views.tv_detail.setText(data.text);
    }

    private static class ViewHolder {
        final ImageView image;
        final Toolbar toolbar;
        final TextView tv_detail;

        ViewHolder(Activity activity) {
            toolbar = Views.find(activity, R.id.toolbar);
            image = Views.find(activity, R.id.image);
            tv_detail = Views.find(activity, R.id.tv_detail);
        }
    }

}
